using log4net;
using log4net.Config;
using SilverSea.Databases;
using SilverSea.Registration;
using SilverSea.Untilities;
using System;
using System.Globalization;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
internal static class Program
{
	[System.STAThread]
	private static void Main()
	{
		Application.EnableVisualStyles();
		Application.SetCompatibleTextRenderingDefault(false);
		LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
		BasicConfigurator.Configure();
		XmlConfigurator.Configure();
		bool flag;
		using (new System.Threading.Mutex(true, "Red Light Violation", out flag))
		{
			if (flag)
			{
				System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(RegisterationInfo.m_Language);
				SystemUntils.GetCurrentSystemSettings();
				SystemUntils.SetStandardSystemSetting();
				CryptorEngine.SetKey("STM - 2011 - 1");
				Register register = new Register(System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\RLDC.ini", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\RLAT.ini", "RL");
                register.HideDemoButton = true;
                register.DayDemo = 0;
				RunType runType = register.ShowDialog();
				if (runType != RunType.Expired)
				{
					bool bool_ = runType == RunType.Demo;
                    RegisterationInfo.m_UserCode = register.UserCode;
                    RegisterationInfo.m_ActivationKey = register.ActivationKey;
					RegisterationInfo.m_RunTimeMode = bool_;
					SystemConfiguration.smethod_0();
					IConnection connection;
					if (SystemConfiguration.m_DbType == 0)
					{
						connection = new SqlServerConnection();
					}
					else
					{
						connection = new AccessConnection();
					}
					connection.ServerName = SystemConfiguration.m_ServerName;
					connection.DatabaseName = SystemConfiguration.m_DatabaseName;
					connection.Authentication = SystemConfiguration.m_Authentication;
					connection.UserName = SystemConfiguration.m_UserName;
					connection.Password = SystemConfiguration.m_Password;
					connection.EnableMARS = SystemConfiguration.m_EnableMARS;
					if (!connection.Open())
					{
						MessageBox.Show("Không thể kết nối đến CSDL.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
						Application.Exit();
					}
					else
					{
						connection.Close();
						Application.Run(new MainForm());
					}
				}
			}
			else
			{
				MessageBox.Show("Chương trình Red Light Violation đang được mở hoặc đang được chạy ngầm. Bạn hãy kiểm tra trong 'Task Manager / Processes'.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				Application.Exit();
			}
		}
	}
}
